<?php

class Application_Model_service_ChucNangSanPhamService implements Application_Model_serviceInf_ChucNangSanPhamServiceInf {
	protected static $_instance=null;
	
	protected function __construct(){
		
	}
	public static function getInstance(){
		if(self::$_instance==null) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	/**
	 * @param string $tenChucNang
	 * @param string $moTa
	 * @param string $hinhIcon
	 */
	public function taoChucNangSanPham($tenChucNang, $moTa, $hinhIcon) {
		//goi lop DAO luu xuong database
		$resutl=0;
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$resutl= $DAO->luuChucNangSanPham($tenChucNang, $moTa, $hinhIcon);
		return $resutl;
	}
	
	/**
	 * @param string $tenChucNang
	 * @param string $moTa
	 * @param string $hinhIcon
	 * 
	 */
	public function suaChucNangSanPham($id,$tenChucNang, $moTa, $hinhIcon) {
		$result=false;
		//goi lop DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->updateChucNangSanPham($id,$tenChucNang, $moTa, $hinhIcon);
		return $result;
	}
	/**
	 * 
	 */
	public function loadAllChucNangSanPham() {
		//goi DAO
		$result=array();
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->getAllChucNangSanPham();
		return $result;
	}
	/**
	 * @param unknown_type $id
	 */
	public function getOneChucNangSanPham($id) {
		$result=null;
		//goi DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->getChucNangSanPham($id);
		return $result;
	}
	/**
	 * @return array in array
	 */
	public function loadAllItemChucNangSanPham() {
		$result=array();
		//goi DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->getAllItemChucNangSanPham();
		return $result;
	}
	/**
	 * @param unknown_type $idNhomChucNang
	 * @param unknown_type $noiDung
	 */
	public function taoItemChucNangSanPham($idNhomChucNang, $noiDung) {
		//GoiDAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=0;
		$result=$DAO->luuItemChucNangSanPham($idNhomChucNang,$noiDung);
		return $result;
	}
	/**
	 * @param unknown_type $id
	 */
	public function getOneItemChucNangSanPham($id) {
		$result=new Application_Model_bean_ItemChucNangSanPham();
		//goi DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->getItemChucNangSanPham($id);
		return $result;
	}

	/**
	 * @param unknown_type $id
	 * @param unknown_type $idNhomChucNang
	 * @param unknown_type $noiDung
	 */
	public function suaItemChucNangSanPham($id, $idNhomChucNang, $noiDung) {
		$result=false;
		//goi DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->updateItemChucNangSanPham($id,$idNhomChucNang,$noiDung);
		return $result;
	}

	/**
	 * @param unknown_type $id
	 */
	public function xoaChucNangSanPham($id) {
		$result=false;
		if($id==1){
			return 'Limit';
		}
		//goi DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		
		// load chuc chuc nang len de lay file hinh xoa di
		$chucNang=$DAO->getChucNangSanPham($id);
		
		//ten file hinh
		$file=$chucNang->getHinhIcon();
		//xoa file so di
		$uploadDir= realpath(APPLICATION_PATH . '/../public/images/sanPham/chucNang');
		$file=$uploadDir.'/'.$file;
		unlink($file);
		
		//xoa duoi database
		$result=$DAO->deleteChucNangSanPham($id);
		return $result;
	}

	/**
	 * @param unknown_type $id
	 */
	public function xoaItemChucNangSanPham($id) {
		$result=false;
		//goi DAO
		$DAO=Application_Model_dataDAO_ChucNangSanPhamDAO::getInstance();
		$result=$DAO->deleteItemChucNangSanPham($id);
		return $result;
	}

	
	

	


}

?>